//
//  ViewController.m
//  YYStarScorePorject
//
//  Created by 蓓蕾 on 2021/11/26.
//

#import "ViewController.h"

#import "YYStarScoreView.h"

@interface ViewController ()<YYStarRateViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    YYStarConfig *configOne = [YYStarConfig new];
    configOne.titleString = @"随意星评分";
    configOne.titleBetweenStarOfSpace = 5;
    configOne.spacingBetweenStars = 5;
    configOne.infoString = @"3.2";
    configOne.infoBetweenStarOfSpace = 5;
    configOne.currentScore = 3.2;
    configOne.style = YYStarRateViewStyleIncompleteStar;
    YYStarScoreView *starOneView = [[YYStarScoreView alloc] initWithConfig:configOne withResultBlock:^(YYStarScoreView * _Nonnull starRateView, CGFloat starRate) {
        starRateView.infoString = [NSString stringWithFormat:@"%.1lf",starRate];
        NSLog(@"当前评分：%lf",starRate);
    }];
    [self.view addSubview:starOneView];
    [starOneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(0);
        make.top.mas_equalTo(self.view.mas_top).mas_offset(60);
        make.height.mas_equalTo(40);
    }];
    
    YYStarConfig *configTwo = [YYStarConfig new];
    configTwo.titleString = @"半星评分";
    configTwo.titleBetweenStarOfSpace = 5;
    configTwo.spacingBetweenStars = 5;
    configTwo.infoString = @"1.5";
    configTwo.infoBetweenStarOfSpace = 5;
    configTwo.currentScore = 1.5;
    configTwo.style = YYStarRateViewStyleHalfStar;
    YYStarScoreView *starTwoView = [[YYStarScoreView alloc] initWithConfig:configTwo withResultBlock:^(YYStarScoreView * _Nonnull starRateView, CGFloat starRate) {
        starRateView.infoString = [NSString stringWithFormat:@"%.1lf",starRate];
        NSLog(@"当前评分：%lf",starRate);
    }];
    [self.view addSubview:starTwoView];
    [starTwoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(0);
        make.top.mas_equalTo(starOneView.mas_bottom).mas_offset(20);
        make.height.mas_equalTo(40);
    }];
    
    YYStarConfig *configThree = [YYStarConfig new];
    configThree.titleString = @"整星评分";
    configThree.titleBetweenStarOfSpace = 5;
    configThree.spacingBetweenStars = 5;
    configThree.infoString = @"4.0";
    configThree.infoBetweenStarOfSpace = 5;
    configThree.currentScore = 4.0;
    configThree.style = YYStarRateViewStyleWholeStar;
    configThree.allowSlideScore = YES;
    YYStarScoreView *starThreeView = [[YYStarScoreView alloc] initWithConfig:configThree withResultBlock:^(YYStarScoreView * _Nonnull starRateView, CGFloat starRate) {
        starRateView.infoString = [NSString stringWithFormat:@"%.1lf",starRate];
        NSLog(@"当前评分：%lf",starRate);
    }];
    [self.view addSubview:starThreeView];
    [starThreeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(0);
        make.top.mas_equalTo(starTwoView.mas_bottom).mas_offset(20);
        make.height.mas_equalTo(40);
    }];

    YYStarScoreView *starView = [[YYStarScoreView alloc] init];
    [self.view addSubview:starView];
    starView.delegate = self;
    starView.style = YYStarRateViewStyleIncompleteStar;
//    starView.allowSlideScore = YES;
    [starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(0);
        make.centerY.mas_equalTo(self.view.mas_centerY).mas_offset(0);
        make.height.mas_equalTo(40);
    }];
}

- (void)starRateView:(YYStarScoreView *)starRateView didSelecteStarAtStarRate:(CGFloat)starRate
{
    NSLog(@"【代理】当前评分：%lf",starRate);
}


@end
